package com.situ.personal.service;

import java.util.List;

import com.situ.personal.dao.DepartmentDao;
import com.situ.personal.entity.Department;
import com.situ.personal.entity.PageInfo;

public class DepartmentService {
	
	DepartmentDao departmentDao = new DepartmentDao();

	public List<Department> findAll() {
		List<Department> list = departmentDao.findAll();
		return list;
	}//findAll()

	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		
		pageInfo.setPageNo(pageNo);
		pageInfo.setPageSize(pageSize);
		
		//总页数
		int count = departmentDao.getTotalPage();
		int totalPage = (int)Math.ceil( (double)count / pageSize); 
		pageInfo.setTotalPage(totalPage);
		
		//每页信息List
		int offset = (pageNo-1)*pageSize;
		List<Department> list = departmentDao.findByPage(offset, pageSize);
		pageInfo.setList(list);
		
		return pageInfo;
	}

	public boolean deleteById(int id) {
		
		boolean isDelete = departmentDao.deleteById(id);
		return isDelete;
	}

	public boolean insertDepartment(String departmentName) {
		boolean isInsert = departmentDao.insertDepartment(departmentName);
		return isInsert;
	}

	public Department selectById(int departmentId) {
		return departmentDao.selectById(departmentId);
	}

	public boolean updateDepartmentInfo(int id, String name) {
		boolean isUpdateDepartmentInfo = departmentDao.updateDepartmentInfo(id,name);
		return isUpdateDepartmentInfo;
	}

}
